from faker import Faker
import sqlite3

faker = Faker(locale='zh_CN')


with sqlite3.connect('example.db') as conn:
# 连接到 SQLite 数据库
# conn = sqlite3.connect('example.db')
    cursor = conn.cursor()  # 创建一个游标对象

# 创建表
# cursor.execute('''
# CREATE TABLE IF NOT EXISTS users (
#     id INTEGER PRIMARY KEY,
#     name TEXT NOT NULL,
#     phone TEXT NOT NULL,
#     age TEXT NOT NULL,
#     sex TEXT NOT NULL,
#     email TEXT NOT NULL
# )
# ''')

    # 插入数据
    name_list = [faker.name() for _ in range(100)]
    phone_list = [faker.phone_number() for _ in range(100)]
    email_list = [faker.email() for _ in range(100)]
    age_list = [faker.random_int(min=18, max=60) for _ in range(100)]
    sex_list = [faker.random_element(elements=('男', '女')) for _ in range(100)]



    for name, email, phone, age, sex in zip(name_list, email_list, phone_list,age_list,sex_list):
        cursor.execute('INSERT INTO users (name, phone,age,sex,email) VALUES (?, ?,?,?,?)', (name,phone,age,sex, email))

    # 提交事务
    conn.commit()

